package com.ruoyi.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.ruoyi.system.domain.AlpElementCalc;
import com.ruoyi.system.service.IAlpCalcService;
import com.ruoyi.system.service.IAlpMonthlyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class AlpCalcServiceImpl implements IAlpCalcService {
    @Autowired
    private IAlpMonthlyService alpMonthlyService;

    @Override
    public HashMap<String,ArrayList<AlpElementCalc>> getAllElementCalc() {
        HashMap<String,ArrayList<AlpElementCalc>> oneSalePrincipalMap = new HashMap<>();
        List<AlpElementCalc> elementCalcList = new ArrayList<>();
        for (int i = 1; i <=12; i++) {
            //数据库中查出 本月 各销售汇报状况
            List<AlpElementCalc> monthElementList = alpMonthlyService.selectAlpMonthlybyMonthId(i);
            elementCalcList.addAll(monthElementList);
        }
        System.out.println("########月度elementCalcList#########"+ JSON.toJSONString(elementCalcList));

        //1销售  n月    按人分组
        for (AlpElementCalc elementCalc: elementCalcList) {
            if (!oneSalePrincipalMap.containsKey(elementCalc.getXsPrincipalName())) {
                ArrayList<AlpElementCalc> oneSaleElementCalcList = new ArrayList<>();
                oneSaleElementCalcList.add(elementCalc);
                oneSalePrincipalMap.put(elementCalc.getXsPrincipalName(), oneSaleElementCalcList);
            } else {
                oneSalePrincipalMap.get(elementCalc.getXsPrincipalName()).add(elementCalc);
            }
        }
        System.out.println("########月度oneSalePrincipalMap#########"+JSON.toJSONString(oneSalePrincipalMap));
        return oneSalePrincipalMap;
    }
}
